// component/footer.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        active: {
            type: String,
            value: 'index'
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        active: 0,
        navs: [{
            icon: 'home-o',
            page: '../../pages/home/home',
            label: '首页',
            name: 'home'
        },
            {
                icon: 'orders-o',
                page: '../../pages/catalog/catalog',
                label: '分类',
                name: 'catalog'
            },
            {
                icon: 'shopping-cart-o',
                page: '../../pages/shoppingcart/shoppingcart',
                label: '购物车',
                name: 'shoppingcart'
            },
            {
                icon: 'manager-o',
                page: '../../pages/userinfo/userinfo',
                label: '我的',
                name: 'userinfo'
            }
        ]
    },

    /**
     * 组件的方法列表
     */
    methods: {
        onChange(event) {
            // event.detail 的值为当前选中项的索引
            let url;
            this.data.navs.forEach(item => {
                if (item.name == event.detail) {
                    url = item.page
                }
            })
            wx.redirectTo({
                url: url
            })
        }
    }
})
